package cn.internship.modules.manage.controller;

import cn.internship.common.utils.R;
import cn.internship.modules.manage.entity.vo.CommonStatInfo;
import cn.internship.modules.manage.entity.vo.IndustyTopList;
import cn.internship.modules.manage.service.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author haha
 * @version 1.0
 * @description TODO
 * @date 2023/2/28 20:57
 */
@RestController
@RequestMapping("/manage/stat")
@Slf4j
@AllArgsConstructor
public class StatController {

    private final StudentInfoService studentInfoService;

    private final TeacherInfoService teacherInfoService;

    private final ClassInfoService classInfoService;

    private final MajorInfoService majorInfoService;

    private final DeptInfoService deptInfoService;

    private final WeeklyRecordService weeklyRecordService;

    private final InternshipReportService internshipReportService;

    private final StatService statService;

    @GetMapping("common")
    public Object common(){
        CommonStatInfo commonStatInfo = new CommonStatInfo();
        commonStatInfo.setStuNum(studentInfoService.count());
        commonStatInfo.setTeaNum(teacherInfoService.count());
        commonStatInfo.setClassNum(classInfoService.count());
        commonStatInfo.setDeptNum(deptInfoService.count());
        commonStatInfo.setMajorNum(majorInfoService.count());
        commonStatInfo.setWeeklyNum(weeklyRecordService.count());
        commonStatInfo.setReportNum(internshipReportService.count());
        return R.ok().put("common",commonStatInfo);
    }

    @GetMapping("majorTop5")
    public Object majorTop5(){
        return R.ok().put("majorTop5",statService.majorTop5());
    }

    @GetMapping("deptTop5")
    public Object deptTop5(){
        return R.ok().put("deptTop5",statService.deptTop5());
    }

    @GetMapping("industyTop10")
    public Object industyTop10(){
        List<IndustyTopList> industyTopLists = statService.industyTop10();
        Map<String, Object> map = new HashMap<>();
        List<String> types = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (IndustyTopList item : industyTopLists){
            types.add(item.getIndustryType());
            values.add(item.getNum());
        }
        map.put("types",types);
        map.put("value",values);
        return R.ok().put("industyTop10",map);
    }


}
